/* eslint-disable no-use-before-define */
import { requestClient } from '#/api/request';

export namespace mdClient {
  export interface GetListParams {
    code: number;
    msg: string;
    rows: [];
    total: number;
  }
}

export namespace mdClientApi {
  export interface clientListParams {
    total: number;
    rows: Row[];
    code: number;
    msg: string;
  }

  export interface Row {
    searchValue: null;
    createBy: string;
    createTime: Date;
    updateBy: string;
    updateTime: Date | null;
    remark: string;
    params: any;
    clientId: number;
    clientCode: string;
    clientName: string;
    clientNick: null | string;
    clientEn: null | string;
    clientDes: null | string;
    clientLogo: null;
    clientType: ClientType;
    address: null | string;
    website: null | string;
    email: null | string;
    tel: null | string;
    contact1: null | string;
    contact1Tel: null | string;
    contact1Email: null | string;
    contact2: null | string;
    contact2Tel: null | string;
    contact2Email: null | string;
    creditCode: null | string;
    enableFlag: EnableFlag;
    attr1: null;
    attr2: null;
    attr3: number;
    attr4: number;
  }

  export enum ClientType {
    Enterprise = 'ENTERPRISE',
    Finished = 'FINISHED',
  }

  export enum EnableFlag {
    N = 'N',
    Y = 'Y',
  }
}

export const getWorkshopList = (params?: {
  itemTypeId?: number;
  page?: number;
  pageSize?: number;
}) => {
  return requestClient.get<mdClient.GetListParams>('/mes/md/client/list', {
    params,
  });
};

// 删除客户
export const deleteClient = (id: string) => {
  return requestClient.delete<mdClientApi.clientListParams>(
    `/mes/md/client/${id}`,
  );
};

// 新增客户
export const addClient = (data: mdClientApi.Row) => {
  return requestClient.post<mdClientApi.clientListParams>(
    '/mes/md/client',
    data,
  );
};

// 修改客户
export const updateClient = (data: mdClientApi.Row) => {
  return requestClient.put<mdClientApi.clientListParams>(
    '/mes/md/client',
    data,
  );
};
